//
//  EmailAuthenticationViewController.m
//  TenThousand
//
//  Created by 我的 on 16/6/22.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "EmailAuthenticationViewController.h"

@interface EmailAuthenticationViewController ()
@property (weak, nonatomic) IBOutlet UITextField *emailTF;
@property (weak, nonatomic) IBOutlet UITextField *verificationTF;
@property (nonatomic, strong)NSString *yanzhengStr;

@end

@implementation EmailAuthenticationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"邮箱认证";
    [self createLeft:[UIImage imageNamed:@"ZHSZicon_03"] leftClick:^{
        [self.navigationController popViewControllerAnimated:YES];
    } right:nil rightClick:nil];
}

- (IBAction)yanZhengAction:(id)sender {
    if ([@""isEqualToString:_emailTF.text]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入邮箱" delegate: nil cancelButtonTitle:@"确定" otherButtonTitles: nil, nil];
        [alert show];
        return;
    }
    NSDictionary *para = @{
                           @"Email":_emailTF.text,
                           };
    [NetWorkManager requestWithType:HttpRequestTypePost withMethodName:@"Api.GetEmailName" withParaments:para withSuccessBlock:^(NSDictionary *object) {
        NSLog(@"%@",object);
        self.yanzhengStr = [object objectForKey:@"Data"][0][@"VerificationCode"];
    } withFailureBlock:^(NSError *error) {
        
    } progress:nil];
}

- (IBAction)clickGetEmail:(UIButton *)sender {
    if (_verificationTF.text != self.yanzhengStr) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"验证码输入错误!" delegate: nil cancelButtonTitle:@"确定" otherButtonTitles: nil, nil];
        [alert show];
        return;
    }
    NSString *loginId = [[NSUserDefaults standardUserDefaults] objectForKey:@"LoginId"];
    NSDictionary *dict = @{
                           @"Email":self.emailTF.text,
                           @"LoginId":loginId
                           };
    [NetWorkManager requestWithType:HttpRequestTypePost withMethodName:@"User.GetEmail" withParaments:dict withSuccessBlock:^(NSDictionary *object) {
        NSLog(@"%@", object);
        [self.navigationController popViewControllerAnimated:YES];
    } withFailureBlock:^(NSError *error) {
        NSLog(@"%@", error);
    } progress:^(float progress) {
        
    }];
    
}

@end
